home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / sm099c.zip / EXAMPLE / INIT.C < prev    next >
C/C++ Source or Header  |  1996-03-03  |  2KB  |  80 lines

  1. #include "example.h"
  2.  
  3. void Initialize ( int iArgC, char *pcArgP[], BALLS *pBalls )
  4. /* Perform everything that's neccessary to run the balls. */
  5. {
  6.    int iC1;
  7.    BALL *pBall;
  8.  
  9.    memset (pBalls, 0, sizeof (BALLS));
  10.  
  11.    InitScreen ();
  12.  
  13.    randomize ();
  14.  
  15.    for (iC1 = 0;
  16.         iC1 < MAXBALLS;
  17.         iC1++)
  18.    {
  19.       pBall = &pBalls->Ball[iC1];
  20.       NEWCOLOR (pBall->iColor);
  21.       pBall->iXPos = random (iScreenW) + 1;
  22.       pBall->iYPos = random (iScreenH) + 1;
  23.       pBall->iHSpeed = (iC1%2) ? NEWSPEED (MAXHSPEED) : -NEWSPEED (MAXHSPEED);
  24.       pBall->iVSpeed = (iC1%2) ? NEWSPEED (MAXVSPEED) : -NEWSPEED (MAXVSPEED);
  25.    }
  26.  
  27.    if (iArgC > 1)
  28.    {
  29.       pBalls->iNr = atoi (pcArgP[1]);
  30.       pBalls->iNr = pBalls->iNr > 0 ? pBalls->iNr : 10;
  31.       pBalls->iNr = pBalls->iNr <= MAXBALLS ? pBalls->iNr : MAXBALLS;
  32.    }
  33.    else
  34.    {
  35.       pBalls->iNr = 10;
  36.    }
  37. }
  38.  
  39. void InitScreen ( void )
  40. /* Prepare screen to show the running balls. */
  41. {
  42.    #ifdef GUI
  43.    #ifdef OS2
  44.    SIZEL Size = { 0, 0 };
  45.    ARCPARAMS ap = { 4, 4, 0, 0 };
  46.    hAB = WinInitialize (0);
  47.    hMQ = WinCreateMsgQueue (hAB, 0);
  48.    WinRegisterClass (hAB, "SillyExample", ClientWndProc, CS_SIZEREDRAW, 0);
  49.    hWndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE | WS_ANIMATE,
  50.                                    &ulFrameFlags,
  51.                                    "SillyExample", "Bounching balls",
  52.                                    0, 0, 100, &hWndClient);
  53.    hDC = WinOpenWindowDC (hWndClient);
  54.    hPS = GpiCreatePS (hAB, hDC, &Size, PU_PELS | GPIF_DEFAULT |
  55.                                        GPIT_MICRO | GPIA_ASSOC);
  56.    GpiSetDrawingMode (hPS, DM_DRAW);
  57.    WinStartTimer (hAB, hWndClient, TID_MOVE, DELAY);
  58.    GpiSetArcParams (hPS, &ap);
  59.    DosSetPriority (0, 1, 31, 0); /* Change to a low priority (IDLE class) */
  60.    #else
  61.    int iErrorCode;
  62.    int iGraphDriver;
  63.    int iGraphMode;
  64.  
  65.    iGraphDriver = DETECT;        /* Request auto-detection */
  66.    initgraph (&iGraphDriver, &iGraphMode, "");
  67.    iErrorCode = graphresult ();  /* Read result of initialization */
  68.    if (iErrorCode != grOk)       /* Error occured during init */
  69.    {
  70.       cprintf ("Graphics System Error: %s\n\r", grapherrormsg (iErrorCode));
  71.       exit (1);
  72.    }
  73.    #endif
  74.    #else
  75.    _setcursortype (_NOCURSOR);
  76.    #endif
  77.    ClrScr ();
  78.    GetScrSize (&iScreenW, &iScreenH);
  79. }
  80.